<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>展示学员信息</title>
    <script src="${pageContext.request.contextPath}/jquery-3.6.0.js"></script>
</head>
<body>
<center >
    <form action="/day05/stu?method=showStu" method="post">
        <p>
            姓名:<input type="text" name="name1" value="${param.name1}">
            性别:<select name="gender1">
            <option value=""  >未选择</option>
            <option value="0"  >男</option>
            <option value="1"  >女</option>
        </select>
            <input type="submit" value="查询">
        </p>
    </form>
</center>
<div style="position: relative;left: 270px">
    <input type="button" value="批量删除" onclick="deleStu()" >
</div>
<table border="1px" width="800px" cellpadding="7px" cellspacing="0px" align="center">
    <tr>
        <th><input type="checkbox" name="all">全选/全不选</th>
        <th>学员编号</th>
        <th>学员名称</th>
        <th>学员性别</th>
        <th>学员爱好</th>
        <th>学员生日</th>
        <th>学员描述</th>
        <th>学员头像</th>
    </tr>
    <c:forEach items="${requestScope.pageBean.list}" var="stu">
        <tr>
            <td >
                <input type="checkbox" name="checkbox" value="${stu.sid}" >
            </td>
            <td>${stu.sid}</td>
            <td>${stu.name}</td>
            <td>${stu.gender}</td>
            <td>${stu.hobby}</td>
            <td>${stu.birthday}</td>
            <td>${stu.intro}</td>
            <td>
                <img src="http://localhost:8080/img/${stu.photo}" width="100px" height="100px">
            </td>
            <td>
                <a href="/day05/stu?method=findStuById&sid=${stu.sid}">修改</a>
            </td>
        </tr>
    </c:forEach>
</table>

<p align="center">
    <a href="/day05/stu?method=showStu&name1=${param.name1}&gender1=${param.gender1}">首页</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <c:if test="${requestScope.pageBean.currentPage == 1}">
        <a href="#">上一页</a>
    </c:if>
    <c:if test="${requestScope.pageBean.currentPage > 1}">
        <a href="/day05/stu?method=showStu&currentPage=${requestScope.pageBean.currentPage-1}&pageSize=${requestScope.pageBean.pageSize}&name1=${param.name1}&gender1=${param.gender1}">
            上一页
        </a>
    </c:if>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <c:if test="${requestScope.pageBean.currentPage == requestScope.pageBean.totalPage}">
        <a href="#">下一页</a>
    </c:if>
    <c:if test="${requestScope.pageBean.currentPage < requestScope.pageBean.totalPage}">
        <a href="/day05/stu?method=showStu&currentPage=${requestScope.pageBean.currentPage+1}&pageSize=${requestScope.pageBean.pageSize}&name1=${param.name1}&gender1=${param.gender1}">
            下一页
        </a>
    </c:if>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="/day05/stu?method=showStu&currentPage=${requestScope.pageBean.totalPage}&pageSize=${requestScope.pageBean.pageSize}&name1=${param.name1}&gender1=${param.gender1}">尾页</a>&nbsp;&nbsp;&nbsp;&nbsp;

    当前 ${requestScope.pageBean.currentPage} 页  &nbsp;&nbsp;
    总条数 ${requestScope.pageBean.totalCount} &nbsp;&nbsp;
    每页显示 ${requestScope.pageBean.pageSize} &nbsp;&nbsp;
    共 ${requestScope.pageBean.totalPage} 页
</p>
<script>
    <%--给全选全不选多选框绑定一个点击事件--%>
    $("input[name=all]").click(function (){
        //this.checked;
        $("input[name=checkbox]").prop("checked",this.checked)
    })

    function deleStu(){
        //获取要删除学生的id 把这些id发送给后台进行删除
        var input = $("input[name=checkbox]:checked");
        var ids = ""; //存放选中的学员的编号【就是多选框选中的那些value值】
        $.each(input,function (index,ele){
            if (index == input.length-1){
                ids += ele.value;
            }else {
                ids += ele.value + ",";
            }
        })
        //alert(ids); 发送请求到后台
        location.href = "/day05/stu?method=deleteStu&ids=" + ids;
    }
</script>
</body>
</html>